package com.tarena.lbs.content.controller;

import com.alibaba.fastjson2.JSON;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.pojo.content.dto.ArticleCategoryDTO;
import com.tarena.lbs.pojo.content.query.ArticleCategoryQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/content/")
public class CategoryController {
    @GetMapping("category/list")
    public Result<PageResult<ArticleCategoryDTO>> catsList(ArticleCategoryQuery query){
        PageResult<ArticleCategoryDTO> pages=assembleCategoryPage();
        return new Result<>(pages);
    }

    /**
     * 手写的假数据
     * @return
     */
    public PageResult<ArticleCategoryDTO> assembleCategoryPage() {
        String catsJson="[\n" +
                "    {\n" +
                "        \"id\": 57,\n" +
                "        \"categoryName\": \"美食\",\n" +
                "        \"sort\": 99,\n" +
                "        \"categoryStatus\": 1,\n" +
                "        \"createTime\": \"2024-06-11 10:07:44\",\n" +
                "        \"updateTime\": \"2024-06-11 10:07:44\"\n" +
                "    },\n" +
                "    {\n" +
                "        \"id\": 58,\n" +
                "        \"categoryName\": \"阅读\",\n" +
                "        \"sort\": 99,\n" +
                "        \"categoryStatus\": 1,\n" +
                "        \"createTime\": \"2024-06-11 10:07:53\",\n" +
                "        \"updateTime\": \"2024-06-11 10:07:53\"\n" +
                "    }\n" +
                "]";
        //将这个list字符串转化成list数据,交给pageResult使用
        List<ArticleCategoryDTO> articleCategoryDTOS = JSON.parseArray(catsJson, ArticleCategoryDTO.class);
        PageResult pageResult=new PageResult();
        pageResult.setPageNo(1);
        pageResult.setPageSize(10);
        pageResult.setTotal(90L);
        pageResult.setObjects(articleCategoryDTOS);
        return pageResult;
    }
}
